package com.ngmaster.apiserver.controller;

import com.alibaba.fastjson.JSON;
import com.ngmaster.apiserver.common.BaseApiResponse;
import com.ngmaster.apiserver.common.DeviceOfflineResponse;
import com.ngmaster.apiserver.common.ResponseStatus;
import com.ngmaster.socket.ByteArray;
import com.ngmaster.socket.CmdType;
import com.ngmaster.socket.NetManager;
import com.ngmaster.socket.ProtocolMessage;
import com.ngmaster.socket.message.*;
import com.ngmaster.socket.util.HexByteUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "下发命令")
@ResponseBody
@CrossOrigin
@RequestMapping("/api")
@Slf4j
public class ApiController {

    /**
     * 发送查询设备信息的协议
     * @param touchMsg 触发发送该协议的cmd
     */
    public void sendCmdQueryDeviceInfo(ProtocolMessage touchMsg) {

        QueryDeviceRunInfoMessage msg = new QueryDeviceRunInfoMessage();
        msg.setCmd(CmdType.QueryDeviceInfo.getCmd());
        msg.setImei(touchMsg.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.QueryDeviceInfo.getDataLength());
        msg.setState((byte)0x00);
        msg.convertHexImeiToBytes();
        msg.serial();
        NetManager.getInstance().getTerminal(touchMsg.getImei()).sendMessage(msg);
    }

    @ApiOperation(value = "绑定套餐", notes = "绑定套餐")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("bind_pricing")
    public BaseApiResponse bindPricing(@RequestBody BindPricingMessage request) {
        warn(JSON.toJSONString(request));
        BindPricingMessage msg = new BindPricingMessage();
        msg.setCmd(CmdType.BindPricing.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.BindPricing.getDataLength());
        msg.setGzms(request.getGzms());
        msg.setDyijlxzdz(request.getDyijlxzdz());
        msg.setDerjlxzdz(request.getDerjlxzdz());
        msg.setDsanjlxzdz(request.getDsanjlxzdz());
        msg.setDsijlxzdz(request.getDsijlxzdz());
        msg.setDwujlxzdz(request.getDwujlxzdz());
        msg.convertHexImeiToBytes();
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "关闭屏幕", notes = "关闭屏幕")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("close_screen")
    public BaseApiResponse closeScreen(@RequestBody ScreenCloseMessage request) {
        warn(JSON.toJSONString(request));
        ScreenCloseMessage msg = new ScreenCloseMessage();
        msg.setCmd(CmdType.ScreenClose.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.ScreenClose.getDataLength());
        msg.setState((byte)0x00);
        msg.convertHexImeiToBytes();
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "打开屏幕", notes = "打开屏幕")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("open_screen")
    public BaseApiResponse openScreen(@RequestBody ScreenOpenMessage request) {
        warn(JSON.toJSONString(request));
        ScreenOpenMessage msg = new ScreenOpenMessage();
        msg.setCmd(CmdType.ScreenOpen.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.ScreenOpen.getDataLength());
        msg.setState((byte)0x00);
        msg.convertHexImeiToBytes();
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "关机", notes = "关机")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("shutdown")
    public BaseApiResponse shutdown(@RequestBody ShutdownMessage request) {
        warn(JSON.toJSONString(request));
        ShutdownMessage msg = new ShutdownMessage();
        msg.setCmd(CmdType.Shutdown.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.Shutdown.getDataLength());
        msg.setState((byte)0x00);
        msg.convertHexImeiToBytes();
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "开机", notes = "开机")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("startup")
    public BaseApiResponse startup(@RequestBody StartUpMessage request) {
        warn(JSON.toJSONString(request));
        StartUpMessage msg = new StartUpMessage();
        msg.setCmd(CmdType.Startup.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.Startup.getDataLength());
        msg.setState((byte)0x00);
        msg.convertHexImeiToBytes();
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "强制冲洗", notes = "强制冲洗")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("force_wash")
    public BaseApiResponse forceWash(@RequestBody ForceWashMessage request) {
        warn(JSON.toJSONString(request));
        ForceWashMessage msg = new ForceWashMessage();
        msg.setCmd(CmdType.ForceWash.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.ForceWash.getDataLength());
        msg.setState((byte)0x00);
        msg.convertHexImeiToBytes();
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "充正值", notes = "充正值")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("add_money")
    public BaseApiResponse addMoney(@RequestBody AddMoneyMessage request) {
        warn(JSON.toJSONString(request));
        AddMoneyMessage msg = new AddMoneyMessage();
        msg.setCmd(CmdType.AddMoney.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.AddMoney.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setCharge(request.getCharge());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "充负值", notes = "充负值")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("sub_money")
    public BaseApiResponse subMoney(@RequestBody SubMoneyMessage request) {
        warn(JSON.toJSONString(request));
        SubMoneyMessage msg = new SubMoneyMessage();
        msg.setCmd(CmdType.SubMoney.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.SubMoney.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setCharge(request.getCharge());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "同步用时", notes = "同步用时")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("sync_day")
    public BaseApiResponse syncDay(@RequestBody SyncDayMessage request) {
        warn(JSON.toJSONString(request));
        SyncDayMessage msg = new SyncDayMessage();
        msg.setCmd(CmdType.SyncTime.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.SyncTime.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setDay(request.getDay());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "查询设备运行信息", notes = "查询设备运行信息")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("req_device_info")
    public BaseApiResponse queryDeviceRunInfo(@RequestBody QueryDeviceRunInfoMessage request) {
        warn(JSON.toJSONString(request));
        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "滤芯发复位与修改", notes = "滤芯发复位与修改")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("filter_update")
    public BaseApiResponse filterUpdate(@RequestBody FilterUpdateMessage request) {
        warn(JSON.toJSONString(request));
        FilterUpdateMessage msg = new FilterUpdateMessage();
        msg.setCmd(CmdType.UpdateFilter.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.UpdateFilter.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setCode1(request.getCode1());
        msg.setCode2(request.getCode2());
        msg.setCode3(request.getCode3());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "切换模式", notes = "切换模式")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("switch_bill_model")
    public BaseApiResponse switchBillModel(@RequestBody SwitchBillModelMessage request) {
        warn(JSON.toJSONString(request));
        SwitchBillModelMessage msg = new SwitchBillModelMessage();
        msg.setCmd(CmdType.SwitchBillModel.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.SwitchBillModel.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setModel(request.getModel());
        msg.setScale(request.getScale());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "恢复出厂设置", notes = "恢复出厂设置")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("wipe_data")
    public BaseApiResponse wipeData(@RequestBody WipeDataMessage request) {
        warn(JSON.toJSONString(request));
        WipeDataMessage msg = new WipeDataMessage();
        msg.setCmd(CmdType.WipeData.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.WipeData.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setState(request.getState());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "休息域名和端口", notes = "休息域名和端口")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("modify_host_port")
    public BaseApiResponse modifyHostPort(@RequestBody ModifyHostPortMessage request) {
        warn(JSON.toJSONString(request));
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "修改心跳间隔", notes = "修改心跳间隔")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("modify_heartbeat_interval")
    public BaseApiResponse modifyHostPort(@RequestBody UpdateHeartbeatIntervalMessage request) {
        warn(JSON.toJSONString(request));
        UpdateHeartbeatIntervalMessage msg = new UpdateHeartbeatIntervalMessage();
        msg.setCmd(CmdType.UpdateHeartbeatInterval.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.UpdateHeartbeatInterval.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setInterval(request.getInterval());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "时间租赁模式，时长记录应用参数 (读取和修改)", notes = "时间租赁模式，时长记录应用参数 (读取和修改)，19号指令")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("rw_run_time")
    public BaseApiResponse rwRuntime(@RequestBody PumpWorkTimeMessage request) {
        warn(JSON.toJSONString(request));
        PumpWorkTimeMessage msg = new PumpWorkTimeMessage();
        msg.setCmd(CmdType.RWPumpWorkTime.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.RWPumpWorkTime.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setMinutes(request.getMinutes());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "读/冲洗时间，单位秒", notes = "读/改冲洗时间，单位秒")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("rw_wash_time")
    public BaseApiResponse modifyWashTime(@RequestBody ReadOrModifyWashTimeMessage request) {
        warn(JSON.toJSONString(request));
        ReadOrModifyWashTimeMessage msg = new ReadOrModifyWashTimeMessage();
        msg.setCmd(CmdType.RWWashTime.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.RWWashTime.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setSeconds(request.getSeconds());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "读/改定时冲洗时间，单位分钟", notes = "读/改定时冲洗时间，单位分钟")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("rw_wash_fix_time")
    public BaseApiResponse rwWashFixTime(@RequestBody ReadOrModifyWashFixedTimeMessage request) {
        warn(JSON.toJSONString(request));
        ReadOrModifyWashFixedTimeMessage msg = new ReadOrModifyWashFixedTimeMessage();
        msg.setCmd(CmdType.RWFixWashTime.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.RWFixWashTime.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setMinutes(request.getMinutes());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "读/改检修时间，单位分钟", notes = "读/改检修时间，单位分钟")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("rw_service_time")
    public BaseApiResponse rwServiceTime(@RequestBody ReadOrModifyServiceTimeMessage request) {
        warn(JSON.toJSONString(request));
        ReadOrModifyServiceTimeMessage msg = new ReadOrModifyServiceTimeMessage();
        msg.setCmd(CmdType.RWServiceTime.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.RWServiceTime.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setMinutes(request.getMinutes());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
//        this.sendCmdQueryDeviceInfo(request);
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "两次水满制水超过1分钟,再次水满冲洗时间，单位秒", notes = "两次水满制水超过1分钟,再次水满冲洗时间，单位秒")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("rw_rewash_time")
    public BaseApiResponse rwReWashTime(@RequestBody ReadOrModifyReWashTimeMessage request) {
        warn(JSON.toJSONString(request));
        ReadOrModifyReWashTimeMessage msg = new ReadOrModifyReWashTimeMessage();
        msg.setCmd(CmdType.RWReWashTime.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.RWReWashTime.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setSeconds(request.getSeconds());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
        return BaseApiResponse.of().withResultSuccess();
    }

    @ApiOperation(value = "获取设备的ICCID", notes = "获取设备的ICCID")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("read_iccid")
    public BaseApiResponse readIccid(@RequestBody ReadIccidFromDeviceMessage request) {
        warn(JSON.toJSONString(request));
        ReadIccidFromDeviceMessage msg = new ReadIccidFromDeviceMessage();
        msg.setCmd(CmdType.ReadIccid.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.ReadIccid.getDataLength());
        msg.convertHexImeiToBytes();
        StringBuilder iccid = new StringBuilder();
        for (int i = 0; i < msg.getImei().length(); i ++) {
            iccid.append("0");
        }
        msg.setIccid(iccid.toString());
        msg.setIccidBytes(HexByteUtil.convertHexStringToBytes(iccid.toString()));
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
        return BaseApiResponse.of().withResultSuccess();
    }


    @ApiOperation(value = "制1升水需要的时间，读写，单位分钟", notes = "制1升水需要的时间，读写，单位分钟")
    @ApiResponse(code = 200, message = "OK", response = BaseApiResponse.class)
    @PostMapping("rw_one_water_of_time")
    public BaseApiResponse rwOneWaterOfTime(@RequestBody ReadOrModifyOneWaterOfTimeMessage request) {
        warn(JSON.toJSONString(request));
        ReadOrModifyOneWaterOfTimeMessage msg = new ReadOrModifyOneWaterOfTimeMessage();
        msg.setCmd(CmdType.OneWaterOfTime.getCmd());
        msg.setImei(request.getImei());
        msg.setByteArray(new ByteArray());
        msg.setDataLength(CmdType.OneWaterOfTime.getDataLength());
        msg.convertHexImeiToBytes();
        msg.setMinutes(request.getMinutes());
        msg.serial();
        boolean sendB = NetManager.getInstance().getTerminal(msg.getImei()).sendMessage(msg);
        if (!sendB) {
            return DeviceOfflineResponse.of().withResultStatus(ResponseStatus.DEVICE_OFFLINE);
        }
        return BaseApiResponse.of().withResultSuccess();
    }

    private void warn(String formatter) {
        log.warn("ReceivedApiRequest:" + formatter);
    }



}
